package com.xinqi.modules.homework.homework.controller.app;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.Param;
import com.xinqi.common.base.response.R;
import com.xinqi.common.core.utils.MessageUtils;
import com.xinqi.common.mybatis.utils.Pages;
import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.modules.homework.homework.dto.req.*;
import com.xinqi.modules.homework.homework.dto.rsp.CourseHomeworkStudentInfoResultDTO;
import com.xinqi.modules.homework.homework.dto.rsp.CourseHomeworkStudentListResultDto;
import com.xinqi.modules.homework.homework.dto.rsp.CourseHomeworkStudentPartakeResultDTO;
import com.xinqi.modules.homework.homework.service.CourseHomeworkStudentLogService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作业学生提交作业信息APP接口
 *
 * @author: system
 * @date: 2023/03/08
 */
@Tag(name = "App-作业学生提交作业信息", description = "作业学生提交作业信息APP接口")
@RestController
@RequestMapping("/app/homework-student")
@RequiredArgsConstructor
public class CourseHomeworkStudentLogAppController {

    private final CourseHomeworkStudentLogService courseHomeworkStudentLogService;

    /**
     * 老师查看所有学生提交作业列表
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @GetMapping("/list")
    public R<CourseHomeworkStudentListResultDto> list(CourseHomeworkStudentLogQueryDTO dto) {
        return R.data(courseHomeworkStudentLogService.homeworkStudentInfoList(dto));
    }


    /**
     * 老师查看所有学生提交作业分页
     */
    @GetMapping("/page")
    public R<PageInfo<CourseHomeworkStudentInfoResultDTO>> page(Param pageable, CourseHomeworkStudentLogQueryDTO dto) {
        PageInfo<CourseHomeworkStudentInfoResultDTO> page = courseHomeworkStudentLogService.homeworkStudentPage(Pages.page(pageable), dto);
        return R.data(page);
    }

    /**
     * 批量操作各种状态查询
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @GetMapping("/list/status")
    public R<List<CourseHomeworkStudentInfoResultDTO>> listStatus(CourseHomeworkStudentBaseDTO dto) {
        return R.data(courseHomeworkStudentLogService.homeworkStudentInfoListByStatus(dto));
    }

    /**
     * 作业参与为参与 0未参与 1已参与
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @GetMapping("/partake/list")
    public R<List<CourseHomeworkStudentPartakeResultDTO>> partakeList(CourseHomeworkStudentLogQueryDTO dto) {
        return R.data(courseHomeworkStudentLogService.partakeList(dto));
    }

    /**
     * 查看学生提交作业详情
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @PostMapping("/detail")
    public R<CourseHomeworkStudentInfoResultDTO> findByParam(@RequestBody CourseHomeworkStudentDetailDTO dto) {
        return R.data(courseHomeworkStudentLogService.findStudentDetail(dto));
    }

    /**
     * 学生端多轮次作业详情选择器：只有多轮次的作业调用
     *
     * @param dto
     * @return
     */
    @PostMapping("/student-repeat-select")
    public R<List<Integer>> studentRepeatSelect(@RequestBody CourseHomeworkStudentDetailDTO dto) {
        dto.setStudentId(LoginHelper.getXqLoginUser().getId());
        return R.data(courseHomeworkStudentLogService.studentRepeatSelect(dto));
    }

    /**
     * 老师端多轮次作业详情选择器：只有多轮次的作业调用
     *
     * @param contentId
     * @return
     */
    @PostMapping("/{contentId}/teacher-repeat-select")
    public R<List<Integer>> teacherRepeatSelect(@PathVariable("contentId") Long contentId) {
        return R.data(courseHomeworkStudentLogService.teacherRepeatSelect(contentId));
    }

    /**
     * 提交作业
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @PostMapping
    public R<String> insert(@Validated @RequestBody CourseHomeworkStudentLogCreateDTO dto) {
        courseHomeworkStudentLogService.insert(dto);
        return R.ok(MessageUtils.message("course.homework.submit.success"));
    }

    /**
     * 催交学生
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @PutMapping("/call")
    public R<String> call(@RequestBody CourseHomeworkStudentLogQueryDTO dto) {
        if (courseHomeworkStudentLogService.call(dto)) {
            return R.ok(MessageUtils.message("course.homework.call.success"));
        } else {
            return R.fail(MessageUtils.message("course.homework.call.fail"));
        }
    }

    /**
     * 打回 学生提交作业
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @PutMapping("/repulse")
    public R<String> repulse(@RequestBody CourseHomeworkStudentLogAllDto dto) {
        if (courseHomeworkStudentLogService.repulse(dto.getList())) {
            return R.ok(MessageUtils.message("course.homework.repulse.success"));
        } else {
            return R.fail(MessageUtils.message("course.homework.repulse.fail"));
        }
    }

    /**
     * 已阅 学生提交作业
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @PutMapping("/read-over")
    public R<String> readOver(@RequestBody CourseHomeworkApproveDto dto) {
        if (courseHomeworkStudentLogService.readOver(dto.getList())) {
            return R.ok(MessageUtils.message("course.homework.read-over.success"));
        } else {
            return R.fail(MessageUtils.message("course.homework.read-over.fail"));
        }
    }

    /**
     * 已批 学生提交的作业
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @PutMapping("/approved")
    public R<String> approved(@RequestBody CourseHomeworkApproveDto dto) {
        if (courseHomeworkStudentLogService.approved(dto.getList())) {
            return R.ok(MessageUtils.message("course.homework.approved.success"));
        } else {
            return R.fail(MessageUtils.message("course.homework.approved.fail"));
        }
    }

    /**
     * 老师添加评语 学生提交的作业
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @PutMapping("/teach-comment")
    public R<String> teachComment(@RequestBody CourseHomeworkApproveDto dto) {
        if (courseHomeworkStudentLogService.teachComment(dto.getList())) {
            return R.ok(MessageUtils.message("course.homework.comment.success"));
        } else {
            return R.fail(MessageUtils.message("course.homework.comment.fail"));
        }
    }

    /**
     * 历史评语
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @GetMapping("/history-comment")
    public R<List<String>> historyComment(CourseHomeworkStudentBaseDTO dto) {
        return R.data(courseHomeworkStudentLogService.historyComment(dto));
    }

    /**
     * 分享 学生提交作业
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @PutMapping("/share")
    public R<String> share(@RequestBody CourseHomeworkStudentLogShareDTO dto) {
        if (courseHomeworkStudentLogService.share(dto)) {
            return R.ok(MessageUtils.message("course.homework.share.success"));
        } else {
            return R.fail(MessageUtils.message("course.homework.share.fail"));
        }
    }

    /**
     * 取消分享 学生提交作业
     */
    @PutMapping("/cancel-share/{studentHomeworkId}")
    public R<Void> cancelShare(@PathVariable Long studentHomeworkId) {
        courseHomeworkStudentLogService.cancelShare(studentHomeworkId);
        return R.ok(MessageUtils.message("取消分享成功"));
    }

    /**
     * 查看 老师分享作业
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @GetMapping("/look-share")
    public R<List<CourseHomeworkStudentInfoResultDTO>> lookShare(CourseHomeworkStudentLogQueryDTO dto) {
        List<CourseHomeworkStudentInfoResultDTO> list = courseHomeworkStudentLogService.findShare(dto);
        return R.ok(list);
    }

}
